# Generated from C:/workspace/mathsolver_engine\mathparser.g4 by ANTLR 4.6
# encoding: utf-8
from __future__ import print_function
from antlr4 import *
from io import StringIO

def serializedATN():
    with StringIO() as buf:
        buf.write(u"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3")
        buf.write(u"\22\62\4\2\t\2\4\3\t\3\3\2\3\2\3\2\5\2\n\n\2\3\3\3\3")
        buf.write(u"\3\3\3\3\3\3\6\3\21\n\3\r\3\16\3\22\3\3\3\3\3\3\3\3\3")
        buf.write(u"\3\3\3\3\3\6\3\34\n\3\r\3\16\3\35\3\3\3\3\3\3\3\3\3\3")
        buf.write(u"\3\3\3\3\7\3\'\n\3\f\3\16\3*\13\3\3\3\3\3\3\3\3\3\5\3")
        buf.write(u"\60\n\3\3\3\2\2\4\2\4\2\5\3\2\3\4\3\2\5\f\3\2\b\13\67")
        buf.write(u"\2\t\3\2\2\2\4/\3\2\2\2\6\n\7\20\2\2\7\b\7\22\2\2\b\n")
        buf.write(u"\5\2\2\2\t\6\3\2\2\2\t\7\3\2\2\2\n\3\3\2\2\2\13\f\t\2")
        buf.write(u"\2\2\f\r\7\16\2\2\r\20\5\4\3\2\16\17\7\21\2\2\17\21\5")
        buf.write(u"\4\3\2\20\16\3\2\2\2\21\22\3\2\2\2\22\20\3\2\2\2\22\23")
        buf.write(u"\3\2\2\2\23\24\3\2\2\2\24\25\7\17\2\2\25\60\3\2\2\2\26")
        buf.write(u"\27\t\3\2\2\27\30\7\16\2\2\30\33\5\4\3\2\31\32\7\21\2")
        buf.write(u"\2\32\34\5\4\3\2\33\31\3\2\2\2\34\35\3\2\2\2\35\33\3")
        buf.write(u"\2\2\2\35\36\3\2\2\2\36\37\3\2\2\2\37 \7\17\2\2 \60\3")
        buf.write(u"\2\2\2!\"\7\20\2\2\"#\7\16\2\2#(\5\4\3\2$%\7\21\2\2%")
        buf.write(u"\'\5\4\3\2&$\3\2\2\2\'*\3\2\2\2(&\3\2\2\2()\3\2\2\2)")
        buf.write(u"+\3\2\2\2*(\3\2\2\2+,\7\17\2\2,\60\3\2\2\2-\60\5\2\2")
        buf.write(u"\2.\60\t\4\2\2/\13\3\2\2\2/\26\3\2\2\2/!\3\2\2\2/-\3")
        buf.write(u"\2\2\2/.\3\2\2\2\60\5\3\2\2\2\7\t\22\35(/")
        return buf.getvalue()


class mathparserParser ( Parser ):

    grammarFileName = "mathparser.g4"

    atn = ATNDeserializer().deserialize(serializedATN())

    decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]

    sharedContextCache = PredictionContextCache()

    literalNames = [ u"<INVALID>", u"'And'", u"'Or'", u"'Rule'", u"'Equal'",
                     u"'Unequal'", u"'Less'", u"'LessEqual'", u"'Greater'",
                     u"'GreaterEqual'", u"'Inequality'", u"<INVALID>", u"'['",
                     u"']'", u"<INVALID>", u"','", u"'-'" ]

    symbolicNames = [ u"<INVALID>", u"<INVALID>", u"<INVALID>", u"<INVALID>",
                      u"<INVALID>", u"<INVALID>", u"<INVALID>", u"<INVALID>",
                      u"<INVALID>", u"<INVALID>", u"<INVALID>", u"WS", u"L_BRACKET",
                      u"R_BRACKET", u"ATOM", u"DELIMITER", u"SUB" ]

    RULE_atom = 0
    RULE_token = 1

    ruleNames =  [ u"atom", u"token" ]

    EOF = Token.EOF
    T__0=1
    T__1=2
    T__2=3
    T__3=4
    T__4=5
    T__5=6
    T__6=7
    T__7=8
    T__8=9
    T__9=10
    WS=11
    L_BRACKET=12
    R_BRACKET=13
    ATOM=14
    DELIMITER=15
    SUB=16

    def __init__(self, input):
        super(mathparserParser, self).__init__(input)
        self.checkVersion("4.6")
        self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
        self._predicates = None



    class AtomContext(ParserRuleContext):

        def __init__(self, parser, parent=None, invokingState=-1):
            super(mathparserParser.AtomContext, self).__init__(parent, invokingState)
            self.parser = parser


        def getRuleIndex(self):
            return mathparserParser.RULE_atom

     
        def copyFrom(self, ctx):
            super(mathparserParser.AtomContext, self).copyFrom(ctx)



    class A1Context(AtomContext):

        def __init__(self, parser, ctx): # actually a mathparserParser.AtomContext)
            super(mathparserParser.A1Context, self).__init__(parser)
            self.copyFrom(ctx)

        def ATOM(self):
            return self.getToken(mathparserParser.ATOM, 0)

        def enterRule(self, listener):
            if hasattr(listener, "enterA1"):
                listener.enterA1(self)

        def exitRule(self, listener):
            if hasattr(listener, "exitA1"):
                listener.exitA1(self)

        def accept(self, visitor):
            if hasattr(visitor, "visitA1"):
                return visitor.visitA1(self)
            else:
                return visitor.visitChildren(self)


    class A2Context(AtomContext):

        def __init__(self, parser, ctx): # actually a mathparserParser.AtomContext)
            super(mathparserParser.A2Context, self).__init__(parser)
            self.copyFrom(ctx)

        def SUB(self):
            return self.getToken(mathparserParser.SUB, 0)
        def atom(self):
            return self.getTypedRuleContext(mathparserParser.AtomContext,0)


        def enterRule(self, listener):
            if hasattr(listener, "enterA2"):
                listener.enterA2(self)

        def exitRule(self, listener):
            if hasattr(listener, "exitA2"):
                listener.exitA2(self)

        def accept(self, visitor):
            if hasattr(visitor, "visitA2"):
                return visitor.visitA2(self)
            else:
                return visitor.visitChildren(self)



    def atom(self):

        localctx = mathparserParser.AtomContext(self, self._ctx, self.state)
        self.enterRule(localctx, 0, self.RULE_atom)
        try:
            self.state = 7
            self._errHandler.sync(self)
            token = self._input.LA(1)
            if token in [mathparserParser.ATOM]:
                localctx = mathparserParser.A1Context(self, localctx)
                self.enterOuterAlt(localctx, 1)
                self.state = 4
                self.match(mathparserParser.ATOM)
                pass
            elif token in [mathparserParser.SUB]:
                localctx = mathparserParser.A2Context(self, localctx)
                self.enterOuterAlt(localctx, 2)
                self.state = 5
                self.match(mathparserParser.SUB)
                self.state = 6
                self.atom()
                pass
            else:
                raise NoViableAltException(self)

        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx

    class TokenContext(ParserRuleContext):

        def __init__(self, parser, parent=None, invokingState=-1):
            super(mathparserParser.TokenContext, self).__init__(parent, invokingState)
            self.parser = parser


        def getRuleIndex(self):
            return mathparserParser.RULE_token

     
        def copyFrom(self, ctx):
            super(mathparserParser.TokenContext, self).copyFrom(ctx)



    class T4Context(TokenContext):

        def __init__(self, parser, ctx): # actually a mathparserParser.TokenContext)
            super(mathparserParser.T4Context, self).__init__(parser)
            self.copyFrom(ctx)

        def atom(self):
            return self.getTypedRuleContext(mathparserParser.AtomContext,0)


        def enterRule(self, listener):
            if hasattr(listener, "enterT4"):
                listener.enterT4(self)

        def exitRule(self, listener):
            if hasattr(listener, "exitT4"):
                listener.exitT4(self)

        def accept(self, visitor):
            if hasattr(visitor, "visitT4"):
                return visitor.visitT4(self)
            else:
                return visitor.visitChildren(self)


    class T5Context(TokenContext):

        def __init__(self, parser, ctx): # actually a mathparserParser.TokenContext)
            super(mathparserParser.T5Context, self).__init__(parser)
            self.copyFrom(ctx)


        def enterRule(self, listener):
            if hasattr(listener, "enterT5"):
                listener.enterT5(self)

        def exitRule(self, listener):
            if hasattr(listener, "exitT5"):
                listener.exitT5(self)

        def accept(self, visitor):
            if hasattr(visitor, "visitT5"):
                return visitor.visitT5(self)
            else:
                return visitor.visitChildren(self)


    class T1Context(TokenContext):

        def __init__(self, parser, ctx): # actually a mathparserParser.TokenContext)
            super(mathparserParser.T1Context, self).__init__(parser)
            self.copyFrom(ctx)

        def L_BRACKET(self):
            return self.getToken(mathparserParser.L_BRACKET, 0)
        def token(self, i=None):
            if i is None:
                return self.getTypedRuleContexts(mathparserParser.TokenContext)
            else:
                return self.getTypedRuleContext(mathparserParser.TokenContext,i)

        def R_BRACKET(self):
            return self.getToken(mathparserParser.R_BRACKET, 0)
        def DELIMITER(self, i=None):
            if i is None:
                return self.getTokens(mathparserParser.DELIMITER)
            else:
                return self.getToken(mathparserParser.DELIMITER, i)

        def enterRule(self, listener):
            if hasattr(listener, "enterT1"):
                listener.enterT1(self)

        def exitRule(self, listener):
            if hasattr(listener, "exitT1"):
                listener.exitT1(self)

        def accept(self, visitor):
            if hasattr(visitor, "visitT1"):
                return visitor.visitT1(self)
            else:
                return visitor.visitChildren(self)


    class T2Context(TokenContext):

        def __init__(self, parser, ctx): # actually a mathparserParser.TokenContext)
            super(mathparserParser.T2Context, self).__init__(parser)
            self.copyFrom(ctx)

        def L_BRACKET(self):
            return self.getToken(mathparserParser.L_BRACKET, 0)
        def token(self, i=None):
            if i is None:
                return self.getTypedRuleContexts(mathparserParser.TokenContext)
            else:
                return self.getTypedRuleContext(mathparserParser.TokenContext,i)

        def R_BRACKET(self):
            return self.getToken(mathparserParser.R_BRACKET, 0)
        def DELIMITER(self, i=None):
            if i is None:
                return self.getTokens(mathparserParser.DELIMITER)
            else:
                return self.getToken(mathparserParser.DELIMITER, i)

        def enterRule(self, listener):
            if hasattr(listener, "enterT2"):
                listener.enterT2(self)

        def exitRule(self, listener):
            if hasattr(listener, "exitT2"):
                listener.exitT2(self)

        def accept(self, visitor):
            if hasattr(visitor, "visitT2"):
                return visitor.visitT2(self)
            else:
                return visitor.visitChildren(self)


    class T3Context(TokenContext):

        def __init__(self, parser, ctx): # actually a mathparserParser.TokenContext)
            super(mathparserParser.T3Context, self).__init__(parser)
            self.copyFrom(ctx)

        def ATOM(self):
            return self.getToken(mathparserParser.ATOM, 0)
        def L_BRACKET(self):
            return self.getToken(mathparserParser.L_BRACKET, 0)
        def token(self, i=None):
            if i is None:
                return self.getTypedRuleContexts(mathparserParser.TokenContext)
            else:
                return self.getTypedRuleContext(mathparserParser.TokenContext,i)

        def R_BRACKET(self):
            return self.getToken(mathparserParser.R_BRACKET, 0)
        def DELIMITER(self, i=None):
            if i is None:
                return self.getTokens(mathparserParser.DELIMITER)
            else:
                return self.getToken(mathparserParser.DELIMITER, i)

        def enterRule(self, listener):
            if hasattr(listener, "enterT3"):
                listener.enterT3(self)

        def exitRule(self, listener):
            if hasattr(listener, "exitT3"):
                listener.exitT3(self)

        def accept(self, visitor):
            if hasattr(visitor, "visitT3"):
                return visitor.visitT3(self)
            else:
                return visitor.visitChildren(self)



    def token(self):

        localctx = mathparserParser.TokenContext(self, self._ctx, self.state)
        self.enterRule(localctx, 2, self.RULE_token)
        self._la = 0 # Token type
        try:
            self.state = 45
            self._errHandler.sync(self)
            la_ = self._interp.adaptivePredict(self._input,4,self._ctx)
            if la_ == 1:
                localctx = mathparserParser.T1Context(self, localctx)
                self.enterOuterAlt(localctx, 1)
                self.state = 9
                _la = self._input.LA(1)
                if not(_la==mathparserParser.T__0 or _la==mathparserParser.T__1):
                    self._errHandler.recoverInline(self)
                else:
                    self._errHandler.reportMatch(self)
                    self.consume()
                self.state = 10
                self.match(mathparserParser.L_BRACKET)
                self.state = 11
                self.token()
                self.state = 14 
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while True:
                    self.state = 12
                    self.match(mathparserParser.DELIMITER)
                    self.state = 13
                    self.token()
                    self.state = 16 
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)
                    if not (_la==mathparserParser.DELIMITER):
                        break

                self.state = 18
                self.match(mathparserParser.R_BRACKET)
                pass

            elif la_ == 2:
                localctx = mathparserParser.T2Context(self, localctx)
                self.enterOuterAlt(localctx, 2)
                self.state = 20
                _la = self._input.LA(1)
                if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << mathparserParser.T__2) | (1 << mathparserParser.T__3) | (1 << mathparserParser.T__4) | (1 << mathparserParser.T__5) | (1 << mathparserParser.T__6) | (1 << mathparserParser.T__7) | (1 << mathparserParser.T__8) | (1 << mathparserParser.T__9))) != 0)):
                    self._errHandler.recoverInline(self)
                else:
                    self._errHandler.reportMatch(self)
                    self.consume()
                self.state = 21
                self.match(mathparserParser.L_BRACKET)
                self.state = 22
                self.token()
                self.state = 25 
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while True:
                    self.state = 23
                    self.match(mathparserParser.DELIMITER)
                    self.state = 24
                    self.token()
                    self.state = 27 
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)
                    if not (_la==mathparserParser.DELIMITER):
                        break

                self.state = 29
                self.match(mathparserParser.R_BRACKET)
                pass

            elif la_ == 3:
                localctx = mathparserParser.T3Context(self, localctx)
                self.enterOuterAlt(localctx, 3)
                self.state = 31
                self.match(mathparserParser.ATOM)
                self.state = 32
                self.match(mathparserParser.L_BRACKET)
                self.state = 33
                self.token()
                self.state = 38
                self._errHandler.sync(self)
                _la = self._input.LA(1)
                while _la==mathparserParser.DELIMITER:
                    self.state = 34
                    self.match(mathparserParser.DELIMITER)
                    self.state = 35
                    self.token()
                    self.state = 40
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)

                self.state = 41
                self.match(mathparserParser.R_BRACKET)
                pass

            elif la_ == 4:
                localctx = mathparserParser.T4Context(self, localctx)
                self.enterOuterAlt(localctx, 4)
                self.state = 43
                self.atom()
                pass

            elif la_ == 5:
                localctx = mathparserParser.T5Context(self, localctx)
                self.enterOuterAlt(localctx, 5)
                self.state = 44
                _la = self._input.LA(1)
                if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << mathparserParser.T__5) | (1 << mathparserParser.T__6) | (1 << mathparserParser.T__7) | (1 << mathparserParser.T__8))) != 0)):
                    self._errHandler.recoverInline(self)
                else:
                    self._errHandler.reportMatch(self)
                    self.consume()
                pass


        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx





